package com.youchuang.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import com.youchuang.bean.IndentItem;
import com.youchuang.common.HibernateConnection;
import com.youchuang.dao.IndentItemDAO;

@Repository("indentItemDAO")
public class IndentItemDAOImpl implements IndentItemDAO {

	private static final String HQL_FIND_BY_USERID = "from IndentItem where userId = :userId";
	private static final String HQL_FIND_BY_INDENTID = "from IndentItem where indentId = :indentId";

	@Resource
	private HibernateConnection<IndentItem> hibernateConnection;

	@Override
	public void save(IndentItem t) {
		hibernateConnection.save(t);
	}

	@Override
	public void delete(IndentItem t) {
		hibernateConnection.delete(t);
	}

	@Override
	public int update(IndentItem t) {
		//Do nothing because of it unusual
		return 0;
	}

	@Override
	public List<IndentItem> queryAll() {
		return null;
	}

	@Override
	public List<IndentItem> queryByIndentId(String indentId) {
		Map<String, Object> params = new HashMap<>();
		params.put("indentId", indentId);
		return hibernateConnection.find(HQL_FIND_BY_INDENTID, params);
	}

	@Override
	public List<IndentItem> queryByUserId(String userId) {
		Map<String, Object> params = new HashMap<>();
		params.put("userId", userId);
		return hibernateConnection.find(HQL_FIND_BY_USERID, params);
	}

}
